import json

import scrapy


class ImgSpider(scrapy.Spider):
    name = 'img'
    allowed_domains = ['image.so.com']
    #start_urls = ['http://image.so.com/']
    row_url ='https://image.so.com/c?ch=beauty'
    start_index = 0
    strat_urls = [row_url.format(start_index)]



    def parse(self, response):
        infos = json.loads(response.body.decode('utf-8'))
        imgs = [info['qhimg_url'] for info in infos['list']]
        yield {'image_urls':imgs}
        self.start_index+=infos['count']
        if infos['count']>0 and self.MAX_NUM>self.start_index:
            yield scrapy.Request(self.row_url.format(self.start_index),callback=self.parse)

